package com.zzl.study.binder;

import com.zzl.study.manager.UserOnlineManager;
import io.micrometer.core.instrument.Gauge;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.binder.MeterBinder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component;

/**
 * @author: zhangzl
 * @date: 2024/3/6 16:15
 * @version: 1.0
 * @description: 在线用户数统计Binder
 */
@Component
public class OnlineUserCountBinder implements MeterBinder {

    @Autowired
    private UserOnlineManager userOnlineManager;

    @Override
    public void bindTo(@NonNull MeterRegistry registry) {
        Gauge.builder("online_user_count", this.userOnlineManager, UserOnlineManager::getOnlineUserCount)
                .baseUnit("人")
                .description("在线人数")
                .tag("system", "user")
                .strongReference(false)
                .register(registry);
    }

}
